﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
//using System.ComponentModel.DataAnnotations.Schema;

namespace CodeCamp.Model
{
    //[Table("cc_SiteUsers")]
    public class SiteUser
    {
        public SiteUser()
        {
            CreatedUTC = DateTime.UtcNow;
        }

        //[Key]
        //[DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        private ICollection<Presenter> _presenters;
        public virtual ICollection<Presenter> Presenters
        {
            get { return _presenters ?? (_presenters = new List<Presenter>()); }
            protected set { _presenters = value; }
        }

        [Required]
        [MaxLength(128)]
        public string FirstName { get; set; }

        [Required]
        [MaxLength(128)]
        public string LastName { get; set; }

        [Required]
        [MaxLength(128)]
        public string EmailAddress { get; set; }

        [Required]
        [MaxLength(256)]
        public string UserIdentityIssuer { get; set; }

        [Required]
        [MaxLength(256)]
        public string UserIdentityProvider { get; set; }

        /// <summary>
        /// Initially, should be "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"
        /// for claims based authentication
        /// </summary>
        [Required]
        [MaxLength(256)]
        public string UserIdentityClaimType { get; set; }

        //TODO: verify maximum sizes of ClaimType, Claim, other Claims based properties
        /// <summary>
        /// If local ASP.Net Membership provider used, this is the login name
        /// If Claims-based auth, is the property of the claim used for identification,
        /// most probably the value from the nameidentifier claim
        /// </summary>
        [Required]
        [MaxLength(512)]
        public string UserIdentityClaim { get; set; }

        /// <summary>
        /// Email address provided claims authentication from claims provider.
        /// Value from "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"
        /// TODO: Figure out what to do if this changes after this presenter has been created
        /// NOTE: This will be null if auth provider is Live ID
        /// </summary>
        [MaxLength(128)]
        public string UserClaimEmailAddress { get; set; }

        /// <summary>
        /// Sufficient space for text representation of IP V6
        /// </summary>
        [MaxLength(50)]
        public string IpAtSignup { get; set; }

        [Required]
        public bool IsApproved { get; set; }

        [Required]
        public bool IsLockedOut { get; set; }

        /// <summary>
        /// Update with logon (using Membership) or postback from claims provider
        /// </summary>
        public Nullable<DateTime> LastLoginUTC { get; set; }

        /// <summary>
        /// Update with each page it to show user online
        /// </summary>
        public Nullable<DateTime> LastOnlineActivityUTC { get; set; }

        [ConcurrencyCheck]
        [Timestamp]
        //[DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Computed)]
        //[Column("Version", TypeName = "rowversion")]
        public byte[] Version { get; protected set; }

        [Required]
        public DateTime CreatedUTC { get; protected set; }

        [Required]
        [MaxLength(128)]
        public string CreatedBy { get; set; }

        public Nullable<DateTime> UpdatedUTC { get; set; }

        [MaxLength(128)]
        public string UpdatedBy { get; set; }

        [Required]
        public bool NewEventEmailOptOut { get; set; }

        private ICollection<EmailItem> _emailItems;
        public virtual ICollection<EmailItem> EmailItems
        {
            get { return _emailItems ?? (_emailItems = new List<EmailItem>()); }
            protected set { _emailItems = value; }
        }

    }
}
